import easygui as g
import os
choices = ['something.txt','something1.txt']
wj=g.choicebox('共有文件如下','文件列表',choices=choices)
button=['覆盖保存','放弃保存','另存为']
if wj != None:
    name = str(wj)
    with open(name) as f1:
        for i in f1:
            f1.seek(0,0)
            str1=f1.read()
    str2=g.textbox('文件【%s】的内容如下'% name,'显示文件内容',str1)
    if str2 != None:
        if str2 != str1:
            cz=g.buttonbox('检查到文件内容发生变化，请选择一下操作','',choices=button)
            if cz != None:
                if cz == '覆盖保存':
                    with open(name,'w') as f2:
                        f2.seek(0,0)
                        f2.writelines(str2)
                    g.msgbox('保存成功')
                elif cz == '放弃保存':
                    g.msgbox('已放弃保存')
                elif cz == '另存为':
                    dir1=g.diropenbox('','','D:\\')
                    os.chdir(dir1)
                    name1 = g.enterbox('请输入你想要保存的文档名称')
                    if name1 != None:
                        with open(name1,'w') as f2:
                            f2.seek(0,0)
                            f2.writelines(str2)
                        g.msgbox('保存成功')
            
        
